using System.Collections;
using UnityEngine;

public class PoolRulesQuickFire : PoolRulesBase
{
	protected QuickFirePlayer m_Player;

	protected override void Start()
	{
		base.Start();
		m_Time = 120f;
		m_Player.PlayTime = 0f;
		m_Player.SetTime(m_Time, immediate: true);
		m_HandleWhiteball = false;
	}

	public override void SetPlayers(params IPlayer[] players)
	{
		m_Player = (QuickFirePlayer)players[0];
	}

	protected override void CustomUpdate()
	{
		if (m_Time > 0f)
		{
			float deltaTime = Time.deltaTime;
			m_Time -= deltaTime;
			m_Player.PlayTime += deltaTime;
		}
		m_Player.SetTime(m_Time);
		if (m_Time <= 0f && base.State != GlobalState.GAMEOVER)
		{
			base.State = GlobalState.GAMEOVER;
			if (PoolRulesBase.onGameOver != null)
			{
				PoolRulesBase.onGameOver(m_Player);
			}
		}
	}

	public override bool CheckGameOver()
	{
		return false;
	}

	public override void PotBall(PoolBall ball, PocketIndexes pocket)
	{
		base.PotBall(ball, pocket);
		if (ball.ballType != 0)
		{
			m_Player.AddBall(ball.GetBallID());
			m_Player.AddScore(100f);
			m_Time += 10f;
		}
	}

	protected override void CallPocket()
	{
	}

	protected override IEnumerator CheckResultAndChangeTurn(float time)
	{
		yield return new WaitForSeconds(time);
		if (m_WhiteBallPotted)
		{
			m_Time -= 30f;
			if (m_Time < 0f)
			{
				m_Time = 0f;
			}
		}
		if (m_PottedBallListThisRound.Count == 0 && !m_WhiteBallPotted)
		{
			m_Player.ComboBreak();
		}
		int i = 0;
		for (int count = m_PottedBallListThisRound.Count; i < count; i++)
		{
			PoolBall poolBall = m_PottedBallListThisRound[i];
			m_PottedBallList.Add(poolBall.GetBallID(), poolBall);
		}
		m_PottedBallListThisRound.Clear();
		TurnBegin();
	}

	protected override bool HandleFouls()
	{
		return false;
	}

	public override void OnBallFired()
	{
		base.OnBallFired();
	}

	protected override void TurnBegin()
	{
		base.TurnBegin();
		if (m_PottedBallList.Count == 14)
		{
			Pools.ResetAllBalls(pottedOnly: true, black8Origin: true);
			m_PottedBallList.Clear();
			m_Player.Rank++;
		}
		GameStatistics.MarkQuickFireHighRound(m_Turn);
	}

	public override void CueBallHitRail()
	{
	}

	public override void Continue()
	{
		string text = string.Format(HOLocalizationConfiguration.GetValue(341), 120f);
		TextDialog.Show(text, OnContinueCallback);
	}

	private void OnContinueCallback()
	{
		m_Time += 120f;
		m_Player.SetTime(m_Time, immediate: true);
		base.State = GlobalState.IDLE;
		TurnBegin();
	}
}
